package utils;

import item.Obiekt;

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.LinkedList;

public class Logger {
	private boolean disabled;

	public Logger() {
		this.disabled = false;
	}

	public Logger(boolean disabled) {
		this.disabled = disabled;
	}

	protected void printBufor(LinkedList<Obiekt> queue) {
		if (queue.size() > 0) {
			for (Obiekt item : queue)
				System.out.print(" " + item.dajID());
		}
		System.out.println();
	}

	/*public void logAddItemToQueue(double time, Obiekt addedItem, Obiekt beingServiced, LinkedList<Obiekt> queue) {
		if (!disabled) {
			time = roundTime(time);
			System.out.print("+K " + addedItem.dajID() + "\t" + time);
			if (beingServiced != null) {
				System.out.print(" " + beingServiced.dajID());
			}
			printBufor(queue);
		}
	}*/

	public void logAddItemToQueue(double time, Obiekt addedItem, LinkedList<Obiekt> queue) {
		if (!disabled) {
			time = roundTime(time);
			System.out.print("+K " + addedItem.dajID() + "\t" + time);
			
			printBufor(queue);
		}
	}
	
	public void logCarStartedToWash(double time, int wascherId, Obiekt servicedItem, LinkedList<Obiekt> queue) {
		if (!disabled) {
			time = roundTime(time);
			System.out.print("+M"+ wascherId + " " + servicedItem.dajID() + "\t" + time);
			printBufor(queue);
		}
	}

	protected double roundTime(double time) {
		time = new BigDecimal(time).round(new MathContext(6)).doubleValue();
		return time;
	}

	public void logCarWashed(double time, int wascherId, Obiekt finishedItem, LinkedList<Obiekt> queue) {
		if (!disabled) {
			time = roundTime(time);
			System.out.print("-M" + wascherId + " " + finishedItem.dajID() + "\t" + time);
			printBufor(queue);
		}
	}
}
